package StudyCode.summary.mydatetime;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class StringToDateTime {
	public static void main(String[] args) {
		LocalDate ld = LocalDate.parse("2019-11-28");
		LocalDateTime ldt = LocalDateTime.parse("2019-11-11T08:44:00");
		System.out.println("解析 Date: " + ld);
		System.out.println("解析 DateTime: " + ldt);

		LocalDate ld2 = LocalDate.parse("2019-11-11", DateTimeFormatter.ISO_DATE);
		System.out.println("ISO 解析器解析: " + ld2);

		try {
			String input = "11/11/2019";
			DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
			LocalDate ld3 = LocalDate.parse(input, formatter);
			System.out.println("自定义解析 Date: " + ld3);
		} catch (DateTimeParseException ex) {
			ex.printStackTrace();
		}
	}
}
